package stu.day33_day38.day36;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class hw4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        int num = s.length() / 4;

        Map<Character, Integer> cntS = new HashMap<>();
        for (char ch : s.toCharArray()) {
            cntS.put(ch, cntS.getOrDefault(ch, 0) + 1);
        }

        Map<Character, Integer> cntSub = new HashMap<>();
        for (Map.Entry<Character, Integer> entry : cntS.entrySet()) {
            if (entry.getValue() > num) {
                cntSub.put(entry.getKey(), entry.getValue() - num);
            }
        }

        if (cntSub.isEmpty()) {
            System.out.println(0);
        } else {
            Map<Character, Integer> cntWin = new HashMap<>();
            int ans = Integer.MAX_VALUE;
            int left = 0;

            for (int right = 0; right < s.length(); right++) {
                char ch = s.charAt(right);
                cntWin.put(ch, cntWin.getOrDefault(ch, 0) + 1);

                while (check(cntWin, cntSub)) {
                    ans = Math.min(ans, right - left + 1);
                    char leftChar = s.charAt(left);
                    cntWin.put(leftChar, cntWin.get(leftChar) - 1);
                    left++;
                }
            }

            System.out.println(ans);
        }
    }

    public static boolean check(Map<Character, Integer> cntWin, Map<Character, Integer> cntSub) {
        for (Map.Entry<Character, Integer> entry : cntSub.entrySet()) {
            if (cntWin.getOrDefault(entry.getKey(), 0) < entry.getValue()) {
                return false;
            }
        }
        return true;
    }



}
